None
%load_ext autoreload
%autoreload 2
from finlab import data,backtest
import finlab
import pandas as pd
import matplotlib.pyplot as plt
from finlab.backtest import sim
from finlab.dataframe import FinlabDataFrame
import pickle
from finlab.plot import plot_tw_stock_candles,plot_tw_stock_treemap
import plotly.express as px
from finlab.tools.event_study import create_factor_data
import tqdm
import numpy as np
import sys
# 自己寫的小工具
sys.path.append("..") # 導入上級目錄
from co_tools import co_get,co_event_analysis,often_use_list,co_event_analysis_real_trade
from finlab_token import token
#付費版token
finlab.login(token())
輸入成功!
data_set_list = often_use_list()
data_set_list
['price:收盤價', 'dividend_tse:最近一次申報每股 (單位)淨值', 'price_earning_ratio:股價淨值比', 'fundamental_features:營業利益率', 'monthly_revenue:當月營收', 'monthly_revenue:上月營收', 'monthly_revenue:去年當月營收', 'financial_statement:每股盈餘', 'price:成交股數', 'financial_statement:股本', 'etl:market_value', 'financial_statement:投資活動之淨現金流入_流出', 'financial_statement:營業活動之淨現金流入_流出', 'fundamental_features:經常稅後淨利', 'financial_statement:股東權益總額', 'fundamental_features:營業利益成長率', 'financial_statement:研究發展費']
#價量
close = co_get('price:收盤價')
vol = co_get('price:成交股數')
market_value = co_get('etl:market_value')
#基本資料
share_capital = co_get('financial_statement:股本')
#制度與行事曆
#損益表
monthly_revenue = co_get('monthly_revenue:當月營收')* 1000
net_operating_revenue = co_get("financial_statement:營業收入淨額")
monthly_revenue_yoy = co_get('monthly_revenue:去年同月增減(%)')
net_income = co_get('fundamental_features:經常稅後淨利')
revenue_growth_rate = co_get('fundamental_features:營業利益成長率')
research = co_get("financial_statement:研究發展費")
#資產負債表
total_equity = co_get('financial_statement:股東權益總額')
#現金流量表
investing_net_cash_flow = co_get('financial_statement:投資活動之淨現金流入_流出')
operating_net_cash_flow = co_get('financial_statement:營業活動之淨現金流入_流出')
從地端載入: "price:收盤價" 從地端載入: "price:成交股數" 從地端載入: "etl:market_value" 從地端載入: "financial_statement:股本" 從地端載入: "monthly_revenue:當月營收" 從地端載入: "financial_statement:營業收入淨額" 從地端載入: "monthly_revenue:去年同月增減(%)" 從地端載入: "fundamental_features:經常稅後淨利" 從地端載入: "fundamental_features:營業利益成長率" 從地端載入: "financial_statement:研究發展費" 從地端載入: "financial_statement:股東權益總額" 從地端載入: "financial_statement:投資活動之淨現金流入_流出" 從地端載入: "financial_statement:營業活動之淨現金流入_流出"
"""
將價格創300天新高當成一個事件,研究這個事件前後報酬率之變化
"""
# 進場條件(事件發生): cross over: 昨日小於等於過去300天高點,而今日大於過去300天高點
buy = (close> close.shift(1).rolling(300).max())&(close.shift(1)<= close.shift(2).rolling(300).max())
event_return = co_event_analysis(buy)
從地端載入: "etl:adj_close"
從地端載入: "benchmark_return:發行量加權股價報酬指數"
100%|██████████████████████████████████████████████████████████████████████████| 49606/49606 [00:10<00:00, 4648.66it/s]
co_event_analysis_real_trade(buy)
C:\Users\f1289\OneDrive\Desktop\sb0487\trade\finlab\因子測試\..\co_tools.py:67: FutureWarning: The default value of numeric_only in DataFrameGroupBy.mean is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.